
vec2 fixuv(in vec2 uv){

    vec2 p = 3.*(2.*uv-iResolution.xy)/min (iResolution.x,iResolution.y);
    return p ;
}

vec4 GridPanel(in vec2 p){

    vec4 col;

    vec2 fraction =1.- 2.*(abs(fract(p))-0.5);
    if(abs(p.x)<=2.*fwidth(p.x)){
        col.r =1.;
    }
    else if(abs(p.y)<=2.*fwidth(p.y)){
        col.g =1.;
    }
    else if(abs(fraction.x)<=1.*fwidth(fraction.x)||abs(fraction.y)<=1.*fwidth(fraction.y)){
        col.xyz = vec3(1);
    } 
    return col;
}

float segment(in vec2 p, in vec2 sp,in vec2 ep,in float w){
float f =0.;
vec2 ba = ep-sp;
vec2 pa = p-sp;
float proj = clamp(dot(ba,pa)/dot(ba,ba),0.,1.);
float d = length(proj*ba-pa);
if(d<=w){
    f =1.;
}
return f;
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){

    vec2 p = fixuv(fragCoord);

    vec4 col = GridPanel(p);
    float s =segment(p,vec2(0.,0.),vec2(1.,3.),21.*fwidth(p.x));
    col.xyz += vec3(s);
    fragColor = col ;
}